//
//  WorkHomeVC.m
//  XLDoctor
//
//  Created by longma on 2018/7/27.
//  Copyright © 2018年 XLH. All rights reserved.
//mj修改名称

#import "SetNameController.h"
@interface SetNameController ()
@property (weak, nonatomic) IBOutlet MJUITextField *titleTextField;
@property (weak, nonatomic) IBOutlet MJUIBaseButton *confirmButton;

@end

@implementation SetNameController


- (void)viewDidLoad {
    [super viewDidLoad];
   
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}

- (void)mj_setUI{
    [super mj_setUI];
    
    if(self.titleItemType == TitleItemTypeNickname){
        self.mj_titleLocalizable = @"Set Nickname";
        self.titleTextField.mj_pLocalizable = @"Nickname";
    }else if(self.titleItemType == TitleItemTypeMemberName){
        self.mj_titleLocalizable = @"Member Name";
        self.titleTextField.mj_pLocalizable = @"Enter name";
    }else if(self.titleItemType == TitleItemTypeGroupName){
        self.mj_titleLocalizable = @"Group Name";
        self.titleTextField.mj_pLocalizable = @"Set your family or company name";
    }else if(self.titleItemType == TitleItemTypeEmailAddress){
        self.mj_titleLocalizable = @"Email Address";
        self.titleTextField.mj_pLocalizable = @"Email address";
    }
//    self.titleTextField.mj_disableThirdPartyKeyboard = true;
    self.titleTextField.text = self.text;
    
    MJWeakSelf
    RAC(self.confirmButton, mj_enabled) = [RACSignal combineLatest:@[self.titleTextField.rac_textSignal] reduce:^id _Nullable(NSString * text){
        
        if(text.length > 0){
            return @(true);
        }
        return @(false);
    }];
    
    [self.confirmButton mj_addAction:^(UIButton *button) {
        
        if(weakSelf.isMyProfile){
            [weakSelf requestData];
        }else{
            if(weakSelf.handleTitleBlock){
                weakSelf.handleTitleBlock(weakSelf.titleTextField.text);
            }
            [weakSelf mj_popViewController];
        }
        
    }];
    
    [self.titleTextField mj_becomeFirstResponder];
}

#pragma mark - 方法
- (void)handleBackButtonClick {
    if(![self.text isEqualToString:self.titleTextField.text] && self.titleTextField.text.length){
        MJWeakSelf
        MJUIAlertViewConfigure *configure = [[MJUIAlertViewConfigure alloc]init];
        configure.confirmButtonColor = UIColor.mj_appColor;
        configure.confirmTitle = MJUILocalizedString(@"Yes");
        configure.cancelTitle = MJUILocalizedString(@"Cancel_qx");
        configure.messageAlignmentCenter = true;
        NSString *messageString = MJUILocalizedString(@"The Information is not saved. Are you sure you want to exit?");
        [MJUIAlertView alertViewWithTitle:MJUILocalizedString(@"Information Not Saved") message:messageString configure:configure confirmBlock:^{
            [weakSelf mj_popViewController];
        } cancelBlock:^{

        }];
    }else{
        [self mj_popViewController];

    }
}
- (void)requestData{
    if(self.titleItemType == TitleItemTypeNickname){
        
    }else if(self.titleItemType == TitleItemTypeGroupName){
        
    }
    if(self.handleTitleBlock)
        self.handleTitleBlock(self.titleTextField.text);
    [self mj_popViewController];

}

#pragma mark - 代理

#pragma mark - 懒加载

@end
